package com.allinpay.merchantweb.common.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;

/**
 * Map对象相关的工具类
 * 
 * @author moliang008
 *
 */
public class MapUtils {

	/**
	 * 将Map的值根据Key升序排序，
	 * 然后根据据Key升序排序所得到的value值连接在一起
	 * 
	 * @param map
	 * @return 根据据Key升序排序所得到的value值连接在一起
	 */
	public static String getMapOrderValues(Map<String, Object> map) {

		if(map ==null || map.size() ==0 )
		{
			return StringUtils.EMPTY;
		}
		
		SortedMap<String, Object> sort = new TreeMap<String, Object>(map);
		Set<Entry<String, Object>> entry1 = sort.entrySet();
		Iterator<Entry<String, Object>> it = entry1.iterator();
		
		StringBuffer orderValues = new StringBuffer();
		
		while (it.hasNext()) {
			
			Entry<String, Object> entry = it.next();
			//空，LIST对象排除在外
			if(entry.getValue() != null && (entry.getValue() instanceof LinkedHashMap==false) && (entry.getValue() instanceof ArrayList==false))
			{
				orderValues.append(String.valueOf(entry.getValue()));
			}
		}
		
		return orderValues.toString();
	}

}